﻿Imports Microsoft.Office.Interop.Word

Public Class MyDocument

    Sub New()
        'bis jetzt nichts
    End Sub

    Sub New(ByVal numberOfItems As Integer)
        Me.New()
        ReDim paragraphs(numberOfItems - 1)
        ReDim globalFormats(3) '4 Formate. Die ersten 2 sind Überschriften.
        Me.insertMockFormats()
    End Sub

    Function indexByFormat(ByVal format As MyFormat) As Integer
        For i As Integer = 0 To (globalFormats.Length - 1)
            If globalFormats(i).isEqual(format) Then
                Return i
            End If
        Next
        Return -1
    End Function

    Sub insertMockFormats()
        Dim title_1 As MyFormat = New MyFormat("Arial", 24, True, False, True, "000000")
        Dim title_2 As MyFormat = New MyFormat("Arial", 16, True, False, False, "0000FF")
        Dim quote As MyFormat = New MyFormat("Cambria", 12, False, True, False, "000000")
        Dim normal As MyFormat = New MyFormat("Calibri", 12, False, False, False, "000000")
        globalFormats(0) = title_1
        globalFormats(1) = title_2
        globalFormats(2) = quote
        globalFormats(3) = normal
    End Sub

    Public paragraphs() As MyParagraph 'kann sowohl ein Abschnitt mit Sätzen sein, als auch Sonderzeichen für Absatz o.ä.
    Public globalFormats() As MyFormat 'Hier werden alle Formate gespeichert

End Class

Public Class MyParagraph

    Sub New()
        empty = False
    End Sub

    Sub New(ByVal numberOfItems As Integer)
        Me.New()
        ReDim sentences(numberOfItems - 1)
    End Sub

    Public sentences() As MySentence
    Public Property empty() As Boolean

End Class

Public Class MySentence

    Sub New()
        Me.index = 0
    End Sub

    Sub New(ByVal numberOfItems As Integer)
        Me.New()
        ReDim words(numberOfItems - 1)
    End Sub

    ' bin nicht mehr sicher, für was das ist...
    Sub cleanArray()
        Dim i As Integer
        For i = 0 To words.Length - 1
            If words(i) Is Nothing Then
                Exit For
            End If
        Next
        If i < words.Length Then
            ReDim Preserve words(i - 1)
        End If
    End Sub

    Public words() As String

    'hier werden alle Sonderzeichen gespeichert. Gibt es Sonderzeichen, dann ist im words-Array an dieser Stelle ein leerer String ("") und stattdessen ist hier das Sonderzeichen vermerkt.
    'Sonderzeichen sind: <TAB> (Tabulator);
    Public specialChars As New Dictionary(Of Integer, String) ' (Index des Wortes (in words), Sonderzeichen)
    Public Property index() As Integer ' Index von 'words', der gerade bearbeitet wird

    Public Property commonFormat() As Integer 'Index des Feldes in "globalFormats"
    Public specialFormat As New Dictionary(Of Integer, Integer) '(Index des Wortes (in words), dazugehöriger Index in "globalFormats")

End Class


Public Class MyFormat

    Sub New()
        font = "Arial"
        size = 12
        bold = False
        italic = False
        underlined = False
        colorCode = "000000" 'BGR
    End Sub

    Sub New(ByVal fontName As String, _
            Optional ByVal fontSize As Integer = 12, _
            Optional ByVal bold As Boolean = False, _
            Optional ByVal italic As Boolean = False, _
            Optional ByVal underlined As Boolean = False, _
            Optional ByVal colorCode As String = "000000")

        Me.New()
        Me.font = fontName
        Me.size = fontSize
        Me.bold = bold
        Me.italic = italic
        Me.underlined = underlined
        Me.colorCode = colorCode
    End Sub

    Sub New(ByVal word As Word.Range) 'Konstruktor, der ein Format anhand des Formats eines Wortes erstellt

        Me.New()
        Me.font = word.Font.Name
        Me.size = word.Font.Size
        Me.bold = word.Font.Bold
        Me.italic = word.Font.Italic
        Me.underlined = (word.Font.Underline > 0)
        Me.colorCode = "000000"
    End Sub

    Public Function isEqual(aFormat As MyFormat) As Boolean

        If Me.font <> aFormat.font Then
            Return False
        End If

        If Me.size <> aFormat.size Then
            Return False
        End If

        If Me.bold <> aFormat.bold Then
            Return False
        End If

        If Me.italic <> aFormat.italic Then
            Return False
        End If

        If Me.underlined <> aFormat.underlined Then
            Return False
        End If

        If Me.colorCode <> aFormat.colorCode Then
            Return False
        End If

        Return True
    End Function

    Public Property font() As String
    Public Property size() As Integer
    Public Property bold() As Boolean
    Public Property italic() As Boolean
    Public Property underlined() As Boolean
    Public Property colorCode() As String

End Class


